package com.hb.trans.utils

import com.hb.trans.delegate.DisqualifyReasonLoader


class ConvertUtils {


    companion object {
        private val disqualifyReasonMap by lazy { DisqualifyReasonLoader().getReasonMap() }

        fun convertToPart(subject: Int): String {
            return when (subject) {
                1 -> "科目一"
                2 -> "科目二"
                3 -> "科目三"
                4 -> "科目四"
                5 -> "全科目套餐"
                else -> ""
            }
        }

        fun convertToPeriodHour(time: Int): String {
            var hour = time / 45
            var minutes = time - hour * 45
            if (time <= 0) {
                hour = 0
                minutes = 0
            } else {
                hour = time / 45
                minutes = time - hour * 45
            }
            return String.format("%d学时%02d分钟", hour, minutes)
        }

        fun convertToHour(time: Int): String {
            val hour = time / 60
            val minutes = time - hour * 60
            return String.format("%d小时%02d分钟", hour, minutes)
        }

        fun convertDisqualifyReason(reason: String): String {
            val sb = StringBuilder()
            var temp =
                if (reason.endsWith(",")) {
                    reason.removeSuffix(",")
                } else {
                    reason
                }
            val reasons = temp.split(",")
            for ((i, r) in reasons.withIndex()) {
                var reasonStr = disqualifyReasonMap[r]
                sb.append("${r}: ${reasonStr}")
                if (i != reasons.size - 1) {
                    sb.append("\n")
                }
            }
            return sb.toString()
        }

        fun convertToUpCase(part: Int): String {
            return when (part) {
                1 -> "一"
                2 -> "二"
                3 -> "三"
                4 -> "四"
                else -> ""
            }
        }
    }
}
